package main

import (
	"algorithms/arrayGenerator"
	"algorithms/linearSearch"
	"fmt"
	"time"
)

func main() {
	data := []Integer{24, 18, 12, 9, 16, 66, 32, 4}
	data0 := []int{24, 18, 12, 9, 16, 66, 32, 4}
	data1 := []user{
		{name: "1", children: []string{"1", "2", "3"}},
		{name: "2", children: []string{"4", "5", "6"}},
	}

	res := linearSearch.Search(data, 16)
	fmt.Println(res)
	res0 := linearSearch.Search0(data0, 16)
	fmt.Println(res0)

	res1 := linearSearch.Search(data, 666)
	fmt.Println(res1)
	res2 := linearSearch.Search0(data0, 666)
	fmt.Println(res2)

	res3 := linearSearch.Search(data1, user{name: "2"})
	fmt.Println(res3)
	res4 := linearSearch.Search0(data1,
		user{name: "2", children: []string{"4", "5", "6"}})
	fmt.Println(res4)

	// 性能测试
	dataSize := []int{1000000, 10000000}
	for _, n := range dataSize {
		data := arrayGenerator.GenerateOrderedArray(n)

		startTime := time.Now().UnixNano()
		for k := 0; k < 100; k++ {
			linearSearch.Search1(data, n)
		}
		endTime := time.Now().UnixNano()

		time := float64(endTime-startTime) / 1000000000
		fmt.Printf("n = %d,100 runs : %f s \n", n, time)
	}
}
